﻿using Microsoft.EntityFrameworkCore;
using TencentCloud.Weilingwith.V20230427.Models;
using ZenSystemService.Api.Data;
using ZenSystemService.Api.Entities;

namespace ZenSystemService.Api.Services
{
    public class TencentAccessTokenService
    {
        private readonly ApplicationDbContext _context;

        public TencentAccessTokenService(ApplicationDbContext context)
        {
            _context = context;
        }

        public IEnumerable<TencentAccessToken> GetAllAccessToken(string AppletSymbol)
        {
            return  _context.TencentAccessTokens.Where(item=>item.AppletSymbol== AppletSymbol).OrderByDescending(item => item.CreateTime).ToList();
        }


        public bool AddTencentAccessToken(TencentAccessToken tencentAccessToken)
        {
            try
            {
                _context.TencentAccessTokens.Add(tencentAccessToken);
                int count = _context.SaveChanges();
                return count > 0 ? true : false;
            }
            catch (Exception ex)
            {
                return false;
            }
        }
    }
}
